package com.ruoyi.front_desk.controller;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.front_desk.FrontdeskPublicOpinion.domain.FrontdeskPublicOpinion;
import com.ruoyi.front_desk.FrontdeskPublicOpinion.domain.FrontdesktempUserInfo;
import com.ruoyi.front_desk.FrontdeskPublicOpinion.mapper.FrontdeskPublicOpinionMapper;
import com.ruoyi.front_desk.Result;
import com.ruoyi.management_controller.PublicOpinion.domain.PublicOpinion;
import com.ruoyi.management_controller.PublicOpinion.mapper.PublicOpinionMapper;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 刘奥旸
 * @version 1.0
 */
@RestController
public class FrontdeskPublicOpinionController {

    @Autowired
    public FrontdeskPublicOpinionMapper frontdeskPublicOpinionMapper;
    @Autowired
    private PublicOpinionMapper publicOpinionMapper;


//传两个字段数据，一个parentid是自己的parentid就是所属街道id，剩下的点击街工委就是街工委role，如果是人大代表就是人大的role
    @GetMapping(value = "/publicopinion/selectuserinfo")
    public List<FrontdesktempUserInfo> a1(@RequestParam int parentId, @RequestParam int role){
        List<FrontdesktempUserInfo> frontdesktempUserInfos =
                frontdeskPublicOpinionMapper.selectByParentIdAndRole(parentId, role);
            return frontdesktempUserInfos;
    }

    @PostMapping(value = "/publicopinion/add")
    public Result a2(@RequestBody PublicOpinion publicOpinion){
        publicOpinionMapper.insertPublicOpinion(publicOpinion);
        return Result.success("民情动态上传完成");
    }

    @GetMapping(value = "/publicopinion/list")
    public Result a3(@RequestParam int id){
        List<FrontdeskPublicOpinion> frontdeskPublicOpinions = frontdeskPublicOpinionMapper.selectByConstituencyId(id);
        return Result.success(frontdeskPublicOpinions);
    }

//    @GetMapping(value = "/publicopinion/findByUserId")
//    public Result findByUserId(@RequestParam int id){
//        List<FrontdeskPublicOpinion> frontdeskPublicOpinions = frontdeskPublicOpinionMapper.selectByConstituencyId(id);
//        return Result.success(frontdeskPublicOpinions);
//    }

    @PutMapping(value = "/publicopinion/update")
    public Result a3(@RequestBody FrontdeskPublicOpinion publicOpinion){
        int i = frontdeskPublicOpinionMapper.updatePublicOpinionById(publicOpinion);
        return Result.success(i);
    }


}
